﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DA
{
    public class ThongTinDonHangDA:BaseConnection
    {
        public SqlDataAdapter danhSachThongTinDonHangAdapter { set; get; }

        public ThongTinDonHangDA()
        {
           
        }
            
        public DataSet timKiemThongTinDonHang(int timKiemTheo, String strchuoiTimKiem)
        {
            DataSet ds = new DataSet();
            String sqlStatement = "";

            IFormatProvider culture = new CultureInfo("fr-FR", true);

            sqlStatement = "SELECT MaDonHang, MaKhachHang, convert(varchar, NgayNhan , 103) AS NgayNhanTmp, convert(varchar, NgayGiao , 103) AS NgayGiaoTmp, NgayNhan, NgayGiao";
            //sqlStatement = "SELECT MaDonHang, MaKhachHang, NgayNhan, NgayGiao";
            sqlStatement += " FROM ThongTinDonHang";
            if (timKiemTheo == 1)
            {
                sqlStatement += " WHERE MaKhachhang = '" + strchuoiTimKiem + "'";

            }else if(timKiemTheo == 2){
                sqlStatement += " WHERE NgayNhan = '" + DateTime.Parse(strchuoiTimKiem,culture).ToString("yyyy/MM/dd") +"'";
		
            }else if(timKiemTheo == 3){
                sqlStatement += " WHERE NgayGiao = '" + DateTime.Parse(strchuoiTimKiem,culture).ToString("yyyy/MM/dd") + "'";
              
            }
            openConnect();
                     
            SqlCommand cmd = new SqlCommand(sqlStatement, con);
            danhSachThongTinDonHangAdapter = new SqlDataAdapter(cmd);
            danhSachThongTinDonHangAdapter.SelectCommand = cmd;
            
            SqlCommandBuilder sqlBuilder = new SqlCommandBuilder(danhSachThongTinDonHangAdapter);
            danhSachThongTinDonHangAdapter.Fill(ds, "ThongTinDonHang");
            closeConnect();
            return ds;         
        }


        public DataSet tiKiemDonHangTheoMaKhachHang(string maKhachHang)
        {
            DataSet ds = new DataSet();

            return ds;
        }
        public DataSet chonDonHang()
        {
            DataSet ds = new DataSet();

            //SqlDataReader myReader = null;
            String sqlStatement = "";
            sqlStatement = "SELECT MaDonHang ";
            sqlStatement += "FROM ThongTinDonHang ";
            sqlStatement += "WHERE NgayGiao > GETDATE() OR NgayGiao IS NULL";

            openConnect();

            SqlCommand cmd = new SqlCommand(sqlStatement, con);
            danhSachThongTinDonHangAdapter = new SqlDataAdapter(cmd);
            danhSachThongTinDonHangAdapter.SelectCommand = cmd;
            SqlCommandBuilder sqlBuilder = new SqlCommandBuilder(danhSachThongTinDonHangAdapter);
            danhSachThongTinDonHangAdapter.Fill(ds, "ThongTinDonHang");
            closeConnect();
            return ds;  

        }
    }
}
